package com.example.springboot_system.serviceImpl;

import com.example.springboot_system.mapper.DepartmentMapper;
import com.example.springboot_system.pojo.Department;
import com.example.springboot_system.pojo.vo.GetDepartmentRspVO;
import com.example.springboot_system.service.AdminService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public List<GetDepartmentRspVO> getDepartment() {
        List<GetDepartmentRspVO> rspVO = new ArrayList<>();

        List<Department> departmentList = departmentMapper.findAll();

        if (departmentList != null && !departmentList.isEmpty()) {

            rspVO.addAll(departmentList.stream().map(department -> {
                GetDepartmentRspVO rsp = new GetDepartmentRspVO();
                BeanUtils.copyProperties(department, rsp);
                return rsp;
            }).collect(Collectors.toList()));
        }
        return rspVO;
    }
}

